package com.itboye.lottery.adapter.base;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.lottery.R;
import com.itboye.lottery.activity.daletou.BascketballMainActivity;
import com.itboye.lottery.alert.ByAlert;
import com.itboye.lottery.bean.BascketballBean;
import com.itboye.lottery.bean.FootballMatchBean;
import com.itboye.lottery.bean.ZqBetListItem;
import com.itboye.lottery.dialog.JclqHHDialog;
import com.itboye.lottery.enums.LotteryType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import static com.itboye.lottery.utils.BetSelectMatches.bascketballHashSet;
import static com.itboye.lottery.utils.BetSelectMatches.bascketballMap;

public class BascketballExpandableListAdapter extends BaseExpandableListAdapter {

    private Activity activity;
    private ArrayList<FootballMatchBean> bascketballMatchBeanArrayList;
    private int pager = 0;
    //    HashMap<String, Map<String, String>> map = new LinkedHashMap<>();
    private int matchCount;
    private ArrayList<ZqBetListItem> zqBetListItemArrayList = new ArrayList<>();

    public ArrayList<ZqBetListItem> getZqBetListItemArrayList() {
        return zqBetListItemArrayList;
    }

    public void setZqBetListItemArrayList(ArrayList<ZqBetListItem> zqBetListItemArrayList) {
        this.zqBetListItemArrayList = zqBetListItemArrayList;
    }

    public int getMatchCount() {
        Log.v("", bascketballMap.toString());
        return matchCount;
    }

    public void setMatchCount(int matchCount) {
        this.matchCount = matchCount;
    }

    public HashMap<String, Map<String, String>> getMap() {
        return bascketballMap;
    }

//    public void setMap(HashMap<String, Map<String, String>> map) {
//        this.map = map;
//    }

    public BascketballExpandableListAdapter(Activity activity, ArrayList<FootballMatchBean> bascketballMatchBeanArrayList) {
        this.activity = activity;
        this.bascketballMatchBeanArrayList = bascketballMatchBeanArrayList;
    }

    @Override
    public int getGroupCount() {
        return bascketballMatchBeanArrayList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return bascketballMatchBeanArrayList.get(i).getBascketballBeanArrayList().size();
    }

    @Override
    public Object getGroup(int i) {
        return bascketballMatchBeanArrayList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return bascketballMatchBeanArrayList.get(i).getBascketballBeanArrayList().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.item_parent, null);
        } else {

        }
        TextView text = view.findViewById(R.id.list_item_parent_title);
        ImageView list_item_parent_icon = view.findViewById(R.id.list_item_parent_icon);
        text.setText(Html.fromHtml(bascketballMatchBeanArrayList.get(i).getGroupTime() + "共<font color='red'>" + bascketballMatchBeanArrayList.get(i).getBascketballBeanArrayList().size() + "</font>场比赛"));
        if (b) {
            list_item_parent_icon.setImageResource(R.mipmap.cz);
        } else {
            list_item_parent_icon.setImageResource(R.mipmap.d0);
        }
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        ChildViewHolder childViewHolder = null;
        BascketballBean matchInfo = bascketballMatchBeanArrayList.get(i).getBascketballBeanArrayList().get(i1);
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.item_lq, null);
            childViewHolder = new ChildViewHolder(view);
            view.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) view.getTag();
        }
        childViewHolder.tv_cn_abbr.setText(matchInfo.getL_cn_abbr());
        childViewHolder.tv_match_end_time.setText(matchInfo.getTime() + "截止");
        childViewHolder.tv_match_number.setText(matchInfo.getNum());
        childViewHolder.home_team_name.setText(matchInfo.getA_cn_abbr());
        childViewHolder.away_team_name.setText(matchInfo.getH_cn_abbr());
//        childViewHolder.tv_match_team_name.setText( matchInfo.getA_cn_abbr()+ "      VS      " +);
        childViewHolder.cb_more.setTag(R.id.tag_1, i);
        childViewHolder.cb_more.setTag(R.id.tag_2, i1);
        resetAllStatus(childViewHolder);
        Log.v("", pager + ">>>>page");
        switch (this.pager) {
            case 0://混合投注
                childViewHolder.ll_hunhe_root.setVisibility(View.VISIBLE);
                addHunTouFrf(matchInfo.getMNL(), childViewHolder, i, i1, 0, "0_frf_", childViewHolder.ll_frf_odds, 0);//非让分胜负
                addHunTouFrf(matchInfo.getHDC(), childViewHolder, i, i1, 1, "1_rf_", childViewHolder.ll_rf_odds, 0);//让分胜负
                setCheckCount(i, i1, childViewHolder);
                break;
            case 1:
                childViewHolder.ll_frf_root.setVisibility(View.VISIBLE);
                addHunTouFrf(matchInfo.getMNL(), childViewHolder, i, i1, 0, "0_frf_", childViewHolder.ll_frf_root, 1);//非让分胜负
                break;
            case 2://让胜负
                childViewHolder.ll_frf_root.setVisibility(View.VISIBLE);
                addHunTouFrf(matchInfo.getHDC(), childViewHolder, i, i1, 1, "1_rf_", childViewHolder.ll_frf_root, 1);//让分胜负
                if (Double.parseDouble(matchInfo.getHDC().getFixedodds()) < 0) {
                    childViewHolder.away_team_name.setText(Html.fromHtml(matchInfo.getH_cn_abbr() + "<font color='blue'>(" + matchInfo.getHDC().getFixedodds() + ")</font>"));
                } else {
                    childViewHolder.away_team_name.setText(Html.fromHtml(matchInfo.getH_cn_abbr() + "<font color='black'>(" + matchInfo.getHDC().getFixedodds() + ")</font>"));
                }
                break;
            case 3://大小分
                childViewHolder.ll_dxf_root.setVisibility(View.VISIBLE);
                addDxf(matchInfo.getHILO(), childViewHolder, i, i1);
                break;
            case 4:
                //胜负差
                addSfc(matchInfo.getWNM(), childViewHolder, i, i1);
                childViewHolder.ll_sfc.setVisibility(View.VISIBLE);
                break;
        }
        return view;
    }

    private void addDxf(BascketballBean.HILOEntity hilo, ChildViewHolder childViewHolder, int gPosition, int cPosition) {
        for (int i = 0; i < childViewHolder.ll_dxf_child_1.getChildCount(); i++) {
            CheckBox checkBox = ((CheckBox) childViewHolder.ll_dxf_child_1.getChildAt(i));
            if (hilo == null) {
                checkBox.setEnabled(false);
                checkBox.setText("未开售");
            } else {
                checkBox.setEnabled(true);
                String dxf = "";
                String peilv = "";
                if (i == 0) {
                    checkBox.setText("大分" + hilo.getH());
                    peilv = hilo.getH();
                    dxf = "大分";
                    checkBox.setEnabled(true);
                } else if (i == 1) {
                    checkBox.setText(hilo.getFixedodds());
                    checkBox.setEnabled(false);
                    checkBox.setTag(R.id.tag_1);
                    dxf = "0";
                    peilv = hilo.getFixedodds();
                } else if (i == 2) {
                    checkBox.setText("小分" + hilo.getL());
                    checkBox.setEnabled(true);
                    peilv = hilo.getL();
                    dxf = "小分";
                }
                StringBuilder tag1 = new StringBuilder("2_dxf_" + i + "_" + dxf + "_" + peilv + "_" + hilo.getSingle());
                checkBox.setTag(tag1);
                checkBox.setChecked(isCheckThisView(tag1.toString(), gPosition + "_" + cPosition + "_" + 2));
                setOnClickListener(gPosition, cPosition, checkBox);
            }
        }
    }

    private void addHunTouFrf(BascketballBean.MNLEntity mnl, ChildViewHolder childViewHolder, int gPosition, int cPosition, int playIndex, String prifix, ViewGroup viewGroup, int type) {
        CheckBox checkBox0;
        CheckBox checkBox1;
        CheckBox checkBox2;
        TextView textView1;
        boolean isSale = false;
        switch (type) {
            case 0:
                checkBox0 = ((CheckBox) viewGroup.getChildAt(1));
                checkBox1 = ((CheckBox) viewGroup.getChildAt(0));
                isSale = setIsSale(mnl, childViewHolder, checkBox0, checkBox1);
                if (isSale) {
                    checkBox0.setText("主胜 " + mnl.getH());
                    StringBuilder tag = new StringBuilder(prifix + 1 + "_主胜_" + mnl.getH() + "_" + mnl.getSingle());
                    checkBox0.setEnabled(true);
                    checkBox0.setTag(tag);
                    checkBox0.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + playIndex));

                    //设置相关属性
                    checkBox1.setText("客胜 " + mnl.getA());
                    tag = new StringBuilder(prifix + 0 + "_客胜_" + mnl.getA() + "_" + mnl.getSingle());
                    checkBox1.setTag(tag);
                    checkBox1.setEnabled(true);
                    checkBox1.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + playIndex));
                    //绑定点击监听
                    setOnClickListener(gPosition, cPosition, checkBox0, checkBox1);
                }
                break;
            case 1:
                checkBox0 = ((CheckBox) viewGroup.getChildAt(2));
                textView1 = ((TextView) viewGroup.getChildAt(1));
                checkBox2 = ((CheckBox) viewGroup.getChildAt(0));
                isSale = setIsSale(mnl, childViewHolder, checkBox0, textView1, checkBox2);
                if (isSale) {
                    checkBox0.setText("主胜 " + mnl.getH());
                    StringBuilder tag = new StringBuilder(prifix + 0 + "_主胜_" + mnl.getH() + "_" + mnl.getSingle());
                    checkBox0.setEnabled(true);
                    checkBox0.setTag(tag);
                    checkBox0.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + playIndex));

                    checkBox2.setText("客胜 " + mnl.getA());
                    tag = new StringBuilder(prifix + 1 + "_客胜_" + mnl.getA() + "_" + mnl.getSingle());
                    checkBox2.setTag(tag);
                    checkBox2.setEnabled(true);
                    checkBox2.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + playIndex));

                    setOnClickListener(gPosition, cPosition, checkBox0, checkBox2);
                }
                break;
        }
        if (playIndex == 1) {
            if (Double.parseDouble(mnl.getFixedodds()) < 0) {
                childViewHolder.tv_rqspf_txt.setText(Html.fromHtml("<font color='blue'>让分<br />" + mnl.getFixedodds() + "</font>"));
            } else {
                childViewHolder.tv_rqspf_txt.setText(Html.fromHtml("<font color='white'>让分<br />" + mnl.getFixedodds() + "</font>"));
            }

        } else {
            childViewHolder.tv_rqspf_txt.setText("让分");
        }

//        if (mnl == null) {
//            ((CheckBox) viewGroup.getChildAt(0)).setText("未开售");
//            (checkBox == null ? textView : checkBox).setText("未开售");
//            ((CheckBox) viewGroup.getChildAt(0)).setEnabled(false);
//            view.setEnabled(false);
//        } else {
//            StringBuilder tag1 = new StringBuilder(prifix + 0 + "_主胜_" + mnl.getH() + "_" + mnl.getSingle());
//            (checkBox == null ? textView : checkBox).setText("客胜 " + mnl.getA());
//            StringBuilder tag2 = new StringBuilder(prifix + 1 + "_客胜_" + mnl.getA() + "_" + mnl.getSingle());
//            ((CheckBox) viewGroup.getChildAt(0)).setEnabled(true);
//            (checkBox == null ? textView : checkBox).setEnabled(true);
//
//            ((CheckBox) viewGroup.getChildAt(0)).setTag(tag1);
//            (checkBox == null ? textView : checkBox).setTag(tag2);
//
//
//            Log.v("checkBox", "tag 让球胜平负   " + tag1.toString());
//            ((CheckBox) viewGroup.getChildAt(0)).setChecked(isCheckThisView(tag1.toString(), gPosition + "_" + cPosition + "_" + playIndex));
//            setOnClickListener(((CheckBox) viewGroup.getChildAt(0)), gPosition, cPosition);
//            if (checkBox != null) {
//                checkBox.setChecked(isCheckThisView(tag2.toString(), gPosition + "_" + cPosition + "_" + playIndex));
//                setOnClickListener(((CheckBox) viewGroup.getChildAt(1)), gPosition, cPosition);
//            }
//
//        }
    }

    private boolean setIsSale(BascketballBean.MNLEntity mnl, ChildViewHolder childViewHolder, View... view) {
        if (mnl == null) {
            for (View view1 : view) {
                if (view1 instanceof CheckBox) {
                    ((CheckBox) view1).setText("未开售");
                }
                view1.setEnabled(false);
            }
            return false;
        } else {
            setIsSingle(childViewHolder.iv_danguan, mnl.getSingle());
        }
        return true;
    }

    private void addSfc(BascketballBean.WNMEntity wnmEntity, ChildViewHolder childViewHolder, int gPosition, int cPosition) {
        String single = "0";
        if (wnmEntity != null) {
            single = wnmEntity.getSingle();
        }
        String[] sfcArray = activity.getResources().getStringArray(R.array.jclq_sfc);
        for (int i = 0; i < childViewHolder.ll_sfc_odds.getChildCount(); i++) {//主胜 3
            CheckBox checkBox = ((CheckBox) childViewHolder.ll_sfc_odds.getChildAt(i));
            String peilv = "";
            try {

                switch (i) {
                    case 0:
                        peilv = wnmEntity.getSpecial_odds().getW1();
                        break;
                    case 1:
                        peilv = wnmEntity.getSpecial_odds().getW2();
                        break;
                    case 2:
                        peilv = wnmEntity.getSpecial_odds().getW3();
                        break;
                    case 3:
                        peilv = wnmEntity.getSpecial_odds().getW4();
                        break;
                    case 4:
                        peilv = wnmEntity.getSpecial_odds().getW5();
                        break;
                    case 5:
                        peilv = wnmEntity.getSpecial_odds().getW6();
                        break;
                }

                StringBuilder tag = new StringBuilder("3_sfc_" + i + "_" + sfcArray[i] + "_" + peilv + "_" + single);
                checkBox.setTag(tag);
                checkBox.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + "3"));
                checkBox.setText(Html.fromHtml(sfcArray[i] + "<br />" + peilv));
                setOnClickListener(gPosition, cPosition, checkBox);
                checkBox.setEnabled(true);
            } catch (Exception e) {
                checkBox.setEnabled(false);
                checkBox.setText("未开售");
            }
        }

        for (int i = 0; i < childViewHolder.ll_sfc_kesheng_odds.getChildCount(); i++) {//客胜 4
            String peilv = "";
            CheckBox checkBox = ((CheckBox) childViewHolder.ll_sfc_kesheng_odds.getChildAt(i));
            try {

                switch (i) {
                    case 0:
                        peilv = wnmEntity.getSpecial_odds().getL1();
                        break;
                    case 1:
                        peilv = wnmEntity.getSpecial_odds().getL2();
                        break;
                    case 2:
                        peilv = wnmEntity.getSpecial_odds().getL3();
                        break;
                    case 3:
                        peilv = wnmEntity.getSpecial_odds().getL4();
                        break;
                    case 4:
                        peilv = wnmEntity.getSpecial_odds().getL5();
                        break;
                    case 5:
                        peilv = wnmEntity.getSpecial_odds().getL6();
                        break;
                }
                StringBuilder tag = new StringBuilder("4_sfc_" + i + "_" + sfcArray[i] + "_" + peilv + "_" + single);
                checkBox.setTag(tag);
                checkBox.setChecked(isCheckThisView(tag.toString(), gPosition + "_" + cPosition + "_" + "4"));
                checkBox.setText(Html.fromHtml(sfcArray[i] + "<br />" + peilv));
                setOnClickListener(gPosition, cPosition, checkBox);
                checkBox.setEnabled(true);
            } catch (Exception e) {
                checkBox.setEnabled(false);
                checkBox.setText("未开售");
            }
        }
        setIsSingle(childViewHolder.iv_danguan, single);
    }

    private void setCheckCount(int i, int i1, ChildViewHolder childViewHolder) {
        Iterator<String> keySet = bascketballMap.keySet().iterator();
        int count = 0;
        while (keySet.hasNext()) {
            String mapKey = keySet.next();
            String str1 = mapKey.split("_")[0];
            String str2 = mapKey.split("_")[1];
//            String str3=mapKey.split("_")[2];
            if (str1.equals(i + "") && str2.equals(i1 + "")) {
                count += bascketballMap.get(mapKey).size();
            }
        }
        if (count == 0) {
            childViewHolder.cb_more.setText("更多玩法");
        } else {
            childViewHolder.cb_more.setText("已选中" + count + "项");
        }

    }

    private void resetAllStatus(ChildViewHolder childViewHolder) {
        childViewHolder.ll_hunhe_root.setVisibility(View.GONE);
        childViewHolder.ll_frf_root.setVisibility(View.GONE);
        childViewHolder.iv_danguan.setVisibility(View.GONE);
        childViewHolder.iv_danguan2.setVisibility(View.GONE);
        childViewHolder.ll_dxf_root.setVisibility(View.GONE);
        childViewHolder.ll_sfc.setVisibility(View.GONE);
        childViewHolder.cb_more.setText("更多玩法");
        childViewHolder.tv_rqspf_txt.setText("让分");
    }


    private void reGetData(CheckBox checkBox, int gPosition, int cPosition) {
        String tags = checkBox.getTag().toString();
        String key = gPosition + "_" + cPosition + "_" + tags.substring(0, 1);
        String value = tags;
        //同一场比赛目前只能限制一种投法
//        if (isSelectCurrentMatch(key)) {
//            ByAlert.alert("一场比赛只能选择一种投注玩法");
//            return;
//        }
        if (isExceedMatchCount(gPosition, cPosition)) {
            return;
        }
        if (bascketballMap.get(key) != null) {
            //有则删除 无则添加 - 等同于没选中则选中 选中了则取消
            if (bascketballMap.get(key).get(value) != null) {
                bascketballMap.get(key).remove(value);
            } else {
                bascketballMap.get(key).put(value, value);
            }
        } else {
            Map<String, String> mapInner = new HashMap<>();
            mapInner.put(value, value);
            bascketballMap.put(key, mapInner);
        }
        if (bascketballMap.get(key) != null && bascketballMap.get(key).values().size() <= 0)
            bascketballMap.remove(key);
        caculateTotalSelectMatches();
    }

    private boolean isSelectCurrentMatch(String key) {
        boolean hasSelect = false;
        Iterator<String> keySet = bascketballMap.keySet().iterator();
        while (keySet.hasNext()) {
            String mapKey = keySet.next();
            String str1 = mapKey.split("_")[0];
            String str2 = mapKey.split("_")[1];
            String str3 = mapKey.split("_")[2];
            if (str1.equals(key.split("_")[0]) && str2.equals(key.split("_")[1])) {
                if (str3.equals(key.split("_")[2])) {

                } else {
                    return true;
                }
            }
        }
//        if (map.get(key) != null) {
//            return true;
////            String betType = key.split("_")[2];//投注玩法
////            map
//        }
        Log.v("", "key---" + key);
        return false;
    }

    private boolean isExceedMatchCount(int gPosition, int cPosition) {
        if (!bascketballHashSet.contains(gPosition + "" + cPosition) && bascketballHashSet.size() >= 8) {
            ByAlert.alert("最多选择八场比赛");
            return true;
        }
        return false;
    }

    public void caculateTotalSelectMatches() {
        Set<String> setKey = bascketballMap.keySet();
        Iterator<String> iterator = setKey.iterator();
        // 从while循环中读取key  自己构造投注单相关信息
        zqBetListItemArrayList = new ArrayList<>();
        bascketballHashSet = new HashSet<>();
        while (iterator.hasNext()) {
            ZqBetListItem zqBetListItem = new ZqBetListItem();
            String cKey = iterator.next();
            String[] keys = cKey.split("_");
            int gP = Integer.parseInt(keys[0]);
            int cP = Integer.parseInt(keys[1]);
            Map<String, String> value = bascketballMap.get(cKey);
            ArrayList<ZqBetListItem.SpfBean> frsfBeanArrayList = new ArrayList<>();
            ArrayList<ZqBetListItem.SpfBean> rfsfBeanArrayList = new ArrayList<>();
            ArrayList<ZqBetListItem.SpfBean> dxfArrayList = new ArrayList<>();
            ArrayList<ZqBetListItem.SpfBean> sfcBeanArrayList = new ArrayList<>();
            for (String s : value.keySet()) {
                String args[] = s.split("_");
                ZqBetListItem.SpfBean bean = new ZqBetListItem.SpfBean();
                if (args[0].equals("0")) {//非让分
                    bean.setKey(args[3]);
                    bean.setValue(args[4]);
                    frsfBeanArrayList.add(bean);
                } else if (args[0].equals("1")) {//让分
                    bean.setKey(args[3]);
                    bean.setValue(args[4]);
                    rfsfBeanArrayList.add(bean);
                } else if (args[0].equals("2")) {//大小分
                    bean.setKey(args[3]);
                    bean.setValue(args[4]);
                    bean.setOtherData(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getHILO().getFixedodds());
                    dxfArrayList.add(bean);
                } else if (args[0].equals("3")) {//胜分差主胜
                    bean.setKey(args[3] + "_" + args[0]);//
                    bean.setValue(args[4]);//赔率值
                    sfcBeanArrayList.add(bean);
                } else if (args[0].equals("4")) {//胜分差客胜
                    bean.setKey(args[3] + "_" + args[0]);//
                    bean.setValue(args[4]);//赔率值
                    sfcBeanArrayList.add(bean);
                }
            }
            bascketballHashSet.add(gP + "" + cP);
            zqBetListItem.setKey(gP + "" + cP);
            zqBetListItem.setEndTime(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getBegin_time());
            zqBetListItem.sethTeam(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getH_cn_abbr());
            zqBetListItem.setaTeam(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getA_cn_abbr());
            zqBetListItem.setDate(bascketballMatchBeanArrayList.get(gP).getGroupTime());
            zqBetListItem.setbDate(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getB_date());
            zqBetListItem.setNum(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getNum_type());
            zqBetListItem.setgPosition(gP);
            zqBetListItem.setcPosition(cP);
            int single = 0;
            switch (pager) {
                case 1:
                    single = Integer.parseInt(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getMNL().getSingle());
                    break;
                case 2:
                    single = Integer.parseInt(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getHDC().getSingle());
                    break;
                case 3:
                    single = Integer.parseInt(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getHILO().getSingle());
                    break;
                case 0:
                case 4:
                    try {
                        single = Integer.parseInt(bascketballMatchBeanArrayList.get(gP).getBascketballBeanArrayList().get(cP).getWNM().getSingle());
                    } catch (Exception e) {
                    }
                    break;
            }
            zqBetListItem.setSingle(single);
            boolean hasAdd = false;
            int position = 0;
            for (int i = 0, zqBetListItemArrayListSize = zqBetListItemArrayList.size(); i < zqBetListItemArrayListSize; i++) {
                ZqBetListItem betListItem = zqBetListItemArrayList.get(i);
                if (betListItem.getKey().equals(gP + "" + cP)) {
                    hasAdd = true;
                    position = i;
                    break;
                } else {
                    hasAdd = false;
                }
            }
            if (!hasAdd) {
                zqBetListItem.setFrsfList(frsfBeanArrayList);
                zqBetListItem.setRfsfList(rfsfBeanArrayList);
                zqBetListItem.setDxfList(dxfArrayList);
                zqBetListItem.setSfcList(sfcBeanArrayList);
                zqBetListItemArrayList.add(zqBetListItem);
            } else {
                zqBetListItemArrayList.get(position).getFrsfList().addAll(frsfBeanArrayList);
                zqBetListItemArrayList.get(position).getRfsfList().addAll(rfsfBeanArrayList);
                zqBetListItemArrayList.get(position).getDxfList().addAll(dxfArrayList);
                zqBetListItemArrayList.get(position).getSfcList().addAll(sfcBeanArrayList);
            }
        }
        ((BascketballMainActivity) activity).getToolbar_hiti().setText(Html.fromHtml(bascketballHashSet.size() <= 0 ? "请选择比赛" : "已选择<font color='red'>" + bascketballHashSet.size() + "</font>场比赛"));
        matchCount = bascketballHashSet.size();
    }

    /**
     * 解析tag参数
     *
     * @param tag
     * @return
     */

    boolean isCheckThisView(String tag, String index) {
        if (bascketballMap == null) return false;
        if (bascketballMap.get(index) != null) {
            return bascketballMap.get(index).get(tag) != null;
        }
        return false;
    }


    private void setOnClickListener(int gPosition, int cPosition, CheckBox... checkBox) {
        for (CheckBox box : checkBox) {
            box.setOnClickListener(view -> {
                reGetData(box, gPosition, cPosition);
                notifyDataSetChanged();
            });
        }

    }

    //是否位单关
    private void setIsSingle(View view, String singleValue) {
        if (singleValue == null) {
            view.setVisibility(View.GONE);
            return;
        }
        //是否单关
        if (singleValue.equalsIgnoreCase("0")) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
    }


    private void showMorePlayTypes(int gPosition, int cPosition, LotteryType lotteryType) {
        JclqHHDialog dialog = new JclqHHDialog(activity, bascketballMatchBeanArrayList, gPosition, cPosition, bascketballMap, lotteryType);
        dialog.setSelectListener((matchInfoArrayList, map1) -> {
            if (isExceedMatchCount(gPosition, cPosition)) {
                return;
            }
            bascketballMap = map1;
            caculateTotalSelectMatches();
            notifyDataSetChanged();
        });
        dialog.show();
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }

    public void setPager(int pager) {
        this.pager = pager;
        bascketballMap = new HashMap<>();
        notifyDataSetChanged();
    }

    public void deleteSelect() {
        if (bascketballMap == null) return;
        if (bascketballMap.size() <= 0) return;
        bascketballMap.clear();
        bascketballMap.clear();
        caculateTotalSelectMatches();
        notifyDataSetChanged();
    }

    class ChildViewHolder {
        CheckBox cb_more;
        TextView tv_cn_abbr, tv_match_number, tv_match_end_time, home_team_name, away_team_name;
        TextView tv_frf_txt, tv_rf_txt;

        LinearLayout ll_hunhe_root, ll_frf_odds, ll_rf_odds, ll_bqc_root, ll_bf_root, ll_zjq_root;

        LinearLayout ll_sfc, ll_frf_root, ll_dxf_root, ll_dxf_child_1;
        LinearLayout ll_bqc_child_1, ll_bqc_child_2, ll_bqc_child_3;
        LinearLayout ll_sfc_odds, ll_sfc_kesheng_odds;
        TextView btn_choose_bf;
        ImageView iv_danguan, iv_danguan2;
        TextView tv_rqspf_txt, tv_spf_txt;

        public ChildViewHolder(View view) {
            cb_more = view.findViewById(R.id.cb_more);
            cb_more.setOnClickListener(view1 -> {
                //更多玩法
                showMorePlayTypes((int) view1.getTag(R.id.tag_1), (int) view1.getTag(R.id.tag_2), LotteryType.SHOWALL);
            });
            tv_cn_abbr = view.findViewById(R.id.tv_cn_abbr);
            tv_match_number = view.findViewById(R.id.tv_match_number);
            tv_match_end_time = view.findViewById(R.id.tv_match_end_time);
            away_team_name = view.findViewById(R.id.away_team_name);//主队
            home_team_name = view.findViewById(R.id.home_team_name);//客队
            ll_hunhe_root = view.findViewById(R.id.ll_hunhe_root);
            ll_frf_odds = view.findViewById(R.id.ll_frf_odds);
            ll_rf_odds = view.findViewById(R.id.ll_rf_odds);
            ll_bqc_root = view.findViewById(R.id.ll_bqc_root);
            ll_bf_root = view.findViewById(R.id.ll_bf_root);
            ll_zjq_root = view.findViewById(R.id.ll_zjq_root);
            btn_choose_bf = view.findViewById(R.id.btn_choose_bf);
            ll_bqc_child_1 = view.findViewById(R.id.ll_bqc_child_1);
            ll_bqc_child_2 = view.findViewById(R.id.ll_bqc_child_2);
            ll_bqc_child_3 = view.findViewById(R.id.ll_bqc_child_3);
            iv_danguan = view.findViewById(R.id.iv_danguan);
            iv_danguan2 = view.findViewById(R.id.iv_danguan2);
            tv_spf_txt = view.findViewById(R.id.tv_spf_txt);
            tv_rqspf_txt = view.findViewById(R.id.tv_rqspf_txt);
            ll_sfc = view.findViewById(R.id.ll_sfc);
            ll_sfc_odds = view.findViewById(R.id.ll_sfc_odds);
            ll_sfc_kesheng_odds = view.findViewById(R.id.ll_sfc_kesheng_odds);
            ll_frf_root = view.findViewById(R.id.ll_frf_root);
            ll_dxf_root = view.findViewById(R.id.ll_dxf_root);
            ll_dxf_child_1 = view.findViewById(R.id.ll_dxf_child_1);
        }

    }
}
